package org.example.grafica;


import java.util.Iterator;
import java.util.List;

import java.util.LinkedList;

import org.example.attivita.Attivita;
import org.example.hellogooglemaps.Coordinata;
import org.example.hellogooglemaps.HelloGoogleMaps;
import org.example.hellogooglemaps.HelloItemizedOverlay;
import org.example.main.CentroCommerciale;
import org.example.main.R;
import org.example.main.SchermataAvvio;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;




public class TabAttivita extends MapActivity implements OnClickListener{
	Drawable selected;
	Drawable unselected;
	RelativeLayout ll;
	RelativeLayout bartel;
	RelativeLayout barmail;
	RelativeLayout barbrow;
	RelativeLayout bar4;
	RelativeLayout bar5;

	
	MapView mapView;
	View tab1;
	View tab2;
	View tab3;
	View tab4;
	public static int status;
	public boolean infofreccia=false;
	View v1;
	View vv;
	View vv2;
	//RESET
	Intent apriPopupBar;
	
	//
	
	//BARRA BOTTOM
	public Drawable bottonebianco;
	public Drawable bottonearancione;
	public RelativeLayout iw;
	public RelativeLayout iw2;
	public RelativeLayout iw3;
	public Drawable Immaginesfondo;
	public Drawable Immaginesfondo2;
	public Drawable Immaginesfondo3;
	public Drawable Immaginesfondoclick;
	public boolean flag=false;
	
	//END BARRA BOTTOM
	public static final String ATTIVITA_CLICCATA = "attivita cliccata";
	LinkedList<Attivita> listaAttivita = new LinkedList<Attivita>();
	Attivita att1;
	Attivita att;
	@Override
	 
	    public void onCreate(Bundle bundle) {

	    		super.onCreate(bundle);
	    		setContentView(R.layout.tab_edit);
	    		status=0;
	    		tab1 =  findViewById(R.id.widget32int);
	    		tab2 =  findViewById(R.id.widget33int);
	    		tab3 =  findViewById(R.id.widget34int);
	    		tab4 =	findViewById(R.id.relmapint);
	    		tab1.setBackgroundColor(Color.WHITE);
	    		tab2.setBackgroundColor(Color.LTGRAY);
	    		tab3.setBackgroundColor(Color.LTGRAY);
	    		tab4.setBackgroundColor(Color.LTGRAY);
	    		tab1.setClickable(true);
	    		tab2.setClickable(true);
	    		tab3.setClickable(true);
	    		tab4.setClickable(true);
	    		
	    		ImageView iget=(ImageView) findViewById(R.id.imGenerale);
	    		Drawable iset=this.getResources().getDrawable(android.R.drawable.ic_menu_agenda);
	    		iget.setImageDrawable(iset);
	    		ImageView iget2=(ImageView) findViewById(R.id.iminfo);
	    		Drawable iset2=this.getResources().getDrawable(android.R.drawable.ic_menu_info_details);
	    		iget2.setImageDrawable(iset2);
	    		ImageView iget3=(ImageView) findViewById(R.id.immap);
	    		Drawable iset3=this.getResources().getDrawable(R.drawable.ic_menu_star);
	    		iget3.setImageDrawable(iset3);
	    		ImageView iget4=(ImageView) findViewById(R.id.immapped);
	    		Drawable iset4=this.getResources().getDrawable(android.R.drawable.ic_menu_mapmode);
	    		iget4.setImageDrawable(iset4);
	    		/////// COMPORTAMENTO BARRA BOTTOM
	    		
	    		TextView tvc = (TextView) this.findViewById(R.id.textV); 
			 	//
			 	bottonebianco =this.getResources().getDrawable(R.drawable.zbutton);
			 	bottonearancione =this.getResources().getDrawable(R.drawable.zbutton_orange);
			 	iw= (RelativeLayout)this.findViewById(R.id.primobottone);
				iw2=(RelativeLayout) this.findViewById(R.id.secondobottone);
				iw3=(RelativeLayout) this.findViewById(R.id.terzobottone);
				Drawable Immaginebottone=this.getResources().getDrawable(android.R.drawable.ic_menu_revert);
				Drawable Immaginebottone2=this.getResources().getDrawable(R.drawable.ic_menu_chat_dashboard);
				Drawable Immaginebottone3=this.getResources().getDrawable(android.R.drawable.ic_menu_set_as);
				ImageView iwi=(ImageView) this.findViewById(R.id.primobottoneimm);
				ImageView iw2i=(ImageView) this.findViewById(R.id.secondobottoneimm);
				ImageView iw3i=(ImageView) this.findViewById(R.id.terzobottoneimm);
				iwi.setImageDrawable(Immaginebottone);
				iw2i.setImageDrawable(Immaginebottone2);
				iw3i.setImageDrawable(Immaginebottone3);
				Drawable Immaginesfondo=this.getResources().getDrawable(R.drawable.timepickerinputnormal);
				Drawable Immaginesfondo2=this.getResources().getDrawable(R.drawable.timepickerinputnormal);
				Drawable Immaginesfondo3=this.getResources().getDrawable(R.drawable.timepickerinputnormal);
				Immaginesfondoclick=this.getResources().getDrawable(R.drawable.timepickerinputselected);
				iw.setBackgroundDrawable(Immaginesfondo);
				iw2.setBackgroundDrawable(Immaginesfondo2);
				iw3.setBackgroundDrawable(Immaginesfondo3);
				iw.setOnClickListener(this);
				iw2.setOnClickListener(this);
				iw3.setOnClickListener(this);
				
				
				
				
	    		///FINE BARRA BOTTOM
	    		
	    		
	    		this.listaAttivita=CentroCommerciale.listaAttivita;
	    		Iterator<Attivita> iter= listaAttivita.iterator();
	 	        att1=new Attivita();
	 	        Bundle extras = getIntent().getExtras();	
	 	        String nomeattivita = extras.getString(TemplateMenuAttivita.ATTIVITA_CLICCATA); 
	 	        

	 	        
			 	        while(iter.hasNext()){
			 		    att1=iter.next();
			 		    	if(att1.getNome().equalsIgnoreCase(nomeattivita)){
			 		    		break;
			 		    		
			 		    	}
			 		    }
			 	        att=att1;
			 	      // View tab3off =  findViewById(R.id.widget34);
			 	       if(att.getOfferte().isEmpty()){
			 	    	  tab3.setBackgroundColor(Color.GRAY);
			 	       }
			 	       
			 	       //else{tab3off.setVisibility(0);}
			 	       
			 	       
			 	       //SET BREDCRUMBS
			 	       tvc.setText(">> Menu >> Negozi >> "+att.getTipologia()+" >> "+nomeattivita);
			 	       tvc.setTextSize(11);
			 	       //END SET BREDC       
			 	      
			 	      
			 	       
			 	       generateScreen(1);
			 	       //generate screen 4
			 	       
			 	       	vv2 = View.inflate(this, R.layout.mainmap, null);
			    		ll.addView(vv2, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
			    		mapView = (MapView)findViewById(R.id.mapview);
			    		mapView.setBuiltInZoomControls(true);	
			    		MapController mc = mapView.getController();	
			    		//mc.animateTo(new GeoPoint(37515189, 15098000)); 
			    		mc.setZoom(15);	
			    		mapView.setSatellite(false);
			    		List<Overlay> mapOverlays = mapView.getOverlays(); 
			    		GeoPoint point1 = new GeoPoint(CentroCommerciale.miaLat().getIntCoordinata(),CentroCommerciale.miaLon().getIntCoordinata());
						GeoPoint point2 = new GeoPoint(att.getLatitudineGeoPoint(), att.getLongitudineGeoPoint());
						//GeoPoint point3 = new GeoPoint(att.getLatitudineGeoPoint(), att.getLongitudineGeoPoint());
						//Coordinata Lat= att.getLatitudine().getCentro(CentroCommerciale.miaLat());
						//Coordinata Lon= att.getLongitudine().getCentro(CentroCommerciale.miaLon());
						Coordinata Lat=CentroCommerciale.miaLat();
						Coordinata Lon=CentroCommerciale.miaLon();
						System.out.println("Coordinate: "+Lat.getIntCoordinata()+" "+Lon.getIntCoordinata());
						System.out.println("Coordinate CC: "+CentroCommerciale.miaLat().getIntCoordinata()+" "+CentroCommerciale.miaLon().getIntCoordinata());
						//GeoPoint pointCenter= new GeoPoint(Lat.getIntCoordinata()+((Lat.getIntCoordinata()-att.getLatitudine().getIntCoordinata())/2),Lon.getIntCoordinata()+((Lon.getIntCoordinata()-att.getLongitudine().getIntCoordinata())/2));
						mc.animateTo(point1);
						int zoom=15;
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<100){zoom=19;}
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))>=100&&(att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<120){zoom=18;}
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))>=120&&(att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<280){zoom=17;}
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))>=280&&(att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<500){zoom=16;}
						mc.setZoom(zoom);
						//Drawable icona=att.getLogoMappa();
						Drawable icona=this.getResources().getDrawable(R.drawable.frecciaverde);
						
						Drawable segnaposto=this.getResources().getDrawable(R.drawable.segnapostorosso);
						
						
						//icona.setImageDrawable(att.getLogoMappa());
						//Drawable iconaIO=this.getResources().getDrawable(R.drawable.frecciaverde);
						Drawable iconaIO=this.getResources().getDrawable(R.drawable.omino);
						
						mapOverlays.add(this.aggiungiAttivitacliccata(icona, point2));
						//mapOverlays.add(this.aggiungiSegnaposto(segnaposto, point2));
			    	    mapOverlays.add(this.aggiungiAttivitacliccata(iconaIO, point1));
			    	    ll.removeView(vv);
			    	    
			    		generateScreen(1);
	
	}
				
	
	//GENERATE SCREEN
    			
	    		
				private void generateScreen(int tabNum) {
	    		
	    		ll = (RelativeLayout) findViewById(R.id.contenitoreinterno);
	    		
	    			if (tabNum == 1) {
	    				vv = View.inflate(this, R.layout.negoziogenerale, null);
	    				ll.addView(vv, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
	    				
	    				RelativeLayout genest= (RelativeLayout) findViewById(R.id.negozioinfo);
			    		genest.setOnClickListener(new TableRow.OnClickListener() { 
				        	  public void onClick(View v) {
				        		  System.out.println("YELLOW");
				        	  	} 
				        	  }); 
	    				//SETTO LA DESCRIZIONE
		    			TextView tv= (TextView) findViewById(R.id.descrizione);
			        	tv.setText(att.getDescrizione());
				        TextView testogrande= (TextView) findViewById(R.id.tGrandegeneral);
				        testogrande.setText(att.getNome());
				        ImageView iw=(ImageView) findViewById(R.id.logim);
				        //debug showInfo(att.getLogo().toString());
				        iw.setImageDrawable(att.getLogo());
	    			} 
	    		
		    		else if (tabNum == 2) {
		    			vv = View.inflate(this, R.layout.negozioinfo, null);
			    		ll.addView(vv, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
			    		RelativeLayout genest= (RelativeLayout) findViewById(R.id.generaleesterno);
			    		genest.setOnClickListener(new TableRow.OnClickListener() { 
				        	  public void onClick(View v) {
				        		  System.out.println("YELLOW");
				        	  	} 
				        	  }); 
			    		TextView Telefono= (TextView) findViewById(R.id.Telefono);
				        Telefono.setText(att.getTelefono());
				        bartel = (RelativeLayout) findViewById(R.id.bar2);
				        bartel.setOnClickListener(this);
				        TextView indirizzo= (TextView) findViewById(R.id.Indirizzo);
				        indirizzo.setText(att.getIndirizzo());
				        TextView Email= (TextView) findViewById(R.id.Email);
				        Email.setText(att.getEmail());
				        barmail = (RelativeLayout) findViewById(R.id.bar1);
				        barmail.setOnClickListener(this);
				        TextView Sito= (TextView) findViewById(R.id.Sito);
				        Sito.setText(att.getSito());
				        barbrow = (RelativeLayout) findViewById(R.id.bar3);
				        barbrow.setOnClickListener(this);
				        bar4 = (RelativeLayout) findViewById(R.id.bar4);
				        bar4.setOnClickListener(this);
				        bar5 = (RelativeLayout) findViewById(R.id.bar5);
				        bar5.setOnClickListener(this);
				        TextView fax= (TextView) findViewById(R.id.Fax);
				        fax.setText(att.getTelefono());
		    			}
				 else if (tabNum ==3 ) {
					 //OFFERTE
					 if(!att.getOfferte().isEmpty()){
					 	vv = View.inflate(this, R.layout.negozioofferte, null);
		    			ll.addView(vv, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
		    			// SETTO LA DESCRIZIONE
		    			RelativeLayout genest= (RelativeLayout) findViewById(R.id.negozioofferte);
			    		genest.setOnClickListener(new TableRow.OnClickListener() { 
				        	  public void onClick(View v) {
				        		  System.out.println("YELLOW");
				        	  	} 
				        	  }); 
		    			TextView tv= (TextView) findViewById(R.id.descrizione);
			        	tv.setText(att.getOfferte().getFirst().getDescrizione());
				        TextView testogrande= (TextView) findViewById(R.id.tGrandegeneral);
				        testogrande.setText(att.getOfferte().getFirst().getNome());
				        testogrande.setGravity(Gravity.CENTER);
				        ImageView iw=(ImageView) findViewById(R.id.logim);
				        iw.setImageDrawable(att.getOfferte().getFirst().getImg());
		    		 }
					
				        
				 }
					 
				 else if (tabNum ==4 ) { 
					 if(!infofreccia){
						infofreccia=true;
						
						 
						 
					 }	
					 
					 /*
						vv2 = View.inflate(this, R.layout.mainmap, null);
			    		ll.addView(vv2, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
			    		mapView = (MapView)findViewById(R.id.mapview);
			    		mapView.setBuiltInZoomControls(true);	
			    		MapController mc = mapView.getController();	
			    		//mc.animateTo(new GeoPoint(37515189, 15098000)); 
			    		mc.setZoom(15);	
			    		mapView.setSatellite(false);
			    		List<Overlay> mapOverlays = mapView.getOverlays(); 
			    		GeoPoint point1 = new GeoPoint(CentroCommerciale.miaLat().getIntCoordinata(),CentroCommerciale.miaLon().getIntCoordinata());
						GeoPoint point2 = new GeoPoint(att.getLatitudineGeoPoint(), att.getLongitudineGeoPoint());
						//GeoPoint point3 = new GeoPoint(att.getLatitudineGeoPoint(), att.getLongitudineGeoPoint());
						//Coordinata Lat= att.getLatitudine().getCentro(CentroCommerciale.miaLat());
						//Coordinata Lon= att.getLongitudine().getCentro(CentroCommerciale.miaLon());
						Coordinata Lat=CentroCommerciale.miaLat();
						Coordinata Lon=CentroCommerciale.miaLon();
						System.out.println("Coordinate: "+Lat.getIntCoordinata()+" "+Lon.getIntCoordinata());
						System.out.println("Coordinate CC: "+CentroCommerciale.miaLat().getIntCoordinata()+" "+CentroCommerciale.miaLon().getIntCoordinata());
						//GeoPoint pointCenter= new GeoPoint(Lat.getIntCoordinata()+((Lat.getIntCoordinata()-att.getLatitudine().getIntCoordinata())/2),Lon.getIntCoordinata()+((Lon.getIntCoordinata()-att.getLongitudine().getIntCoordinata())/2));
						mc.animateTo(point1);
						int zoom=15;
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<100){zoom=19;}
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))>=100&&(att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<120){zoom=18;}
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))>=120&&(att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<280){zoom=17;}
						if((att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))>=280&&(att.getDistanzaDaMe(CentroCommerciale.miaLat(), CentroCommerciale.miaLon()))<500){zoom=16;}
						mc.setZoom(zoom);
						Drawable icona=att.getLogoMappa();
						Drawable segnaposto=this.getResources().getDrawable(R.drawable.segnapostorosso);
						//icona.setImageDrawable(att.getLogoMappa());
						Drawable iconaIO=this.getResources().getDrawable(R.drawable.frecciaverde);
						mapOverlays.add(this.aggiungiAttivitacliccata(icona, point2));
						mapOverlays.add(this.aggiungiSegnaposto(segnaposto, point2));
			    	    mapOverlays.add(this.aggiungiAttivitacliccata(iconaIO, point1));
					 	*/
					 }
				 	
	    		setListeners();
		    		
	    		}
				
	    		private void setListeners() {
	    			
		    		
	    		//TextView tab1 = (TextView) findViewById(R.id.tab1);
	    		tab1.setOnClickListener(onClickListener);
	    		//TextView tab2 = (TextView) findViewById(R.id.tab2);
	    		tab2.setOnClickListener(onClickListener);
	    		//TextView tab3 = (TextView) findViewById(R.id.tab3);
	    		tab3.setOnClickListener(onClickListener);
	    		
	    		tab4.setOnClickListener(onClickListener);
	    		
	    		}
	    			
	    			
	    		// GENERATE SCREEN
	    		
	    		private OnClickListener onClickListener = new OnClickListener() {

	    			public void onClick(View v) {
	    				System.out.println(v.getId());
	    				LayoutParams parUnselected=new LayoutParams(79, 61);
			    		LayoutParams parUnselectedT1=new LayoutParams(78, 61);
			    		LayoutParams parSelected=new LayoutParams(79, 62);
			    		LayoutParams parSelectedT1=new LayoutParams(78, 62);
	    				parUnselectedT1.setMargins(1, 0, 0, 0);
	    				parSelectedT1.setMargins(1, 0, 0, 0);
			    		switch (v.getId()) {
	    				
				    		case R.id.widget32int:
				    		System.out.println("tab1");
				    		tab1.setBackgroundColor(Color.WHITE);
				    		tab2.setBackgroundColor(Color.LTGRAY);
				    		if(!att.getOfferte().isEmpty()){tab3.setBackgroundColor(Color.LTGRAY);}
				    		tab4.setBackgroundColor(Color.LTGRAY);
				    		tab1.setLayoutParams(parSelectedT1);
				    		tab2.setLayoutParams(parUnselected);
				    		tab3.setLayoutParams(parUnselected);
				    		tab4.setLayoutParams(parUnselected);
				    		ll.removeView(vv);
				    		generateScreen(1);
				    		
			
				    		break;
			
				    		case R.id.widget33int:
				    		System.out.println("tab2");
				    		tab2.setBackgroundColor(Color.WHITE);
				    		tab1.setBackgroundColor(Color.LTGRAY);
				    		if(!att.getOfferte().isEmpty()){tab3.setBackgroundColor(Color.LTGRAY);}
				    		tab4.setBackgroundColor(Color.LTGRAY);
				    		tab1.setLayoutParams(parUnselectedT1);
				    		tab3.setLayoutParams(parUnselected);
				    		tab4.setLayoutParams(parUnselected);
				    		tab2.setLayoutParams(parSelected);
				    		ll.removeView(vv);
				    		generateScreen(2);
			
				    		break;
			
				    		case R.id.widget34int:
				    		if(!att.getOfferte().isEmpty()){
				    		System.out.println("tab3");
				    		tab3.setBackgroundColor(Color.WHITE);
				    		tab1.setBackgroundColor(Color.LTGRAY);
				    		tab2.setBackgroundColor(Color.LTGRAY);
				    		tab4.setBackgroundColor(Color.LTGRAY);
				    		tab1.setLayoutParams(parUnselectedT1);
				    		tab4.setLayoutParams(parUnselected);
				    		tab2.setLayoutParams(parUnselected);
				    		tab3.setLayoutParams(parSelected);
				    		ll.removeView(vv);
				    		generateScreen(3);
				    		}
				    		else{
				    		//generateScreen(5);
				    		showInfo("Nessuna offerta disponibile");
				    		}
				    		break;
				    		
				    		case R.id.relmapint:
				    			System.out.println("tab4");
					    		tab4.setBackgroundColor(Color.WHITE);
					    		tab1.setBackgroundColor(Color.LTGRAY);
					    		tab2.setBackgroundColor(Color.LTGRAY);
					    		if(!att.getOfferte().isEmpty()){tab3.setBackgroundColor(Color.LTGRAY);}
					    		tab1.setLayoutParams(parUnselectedT1);
					    		tab3.setLayoutParams(parUnselected);
					    		tab2.setLayoutParams(parUnselected);
					    		tab4.setLayoutParams(parSelected);
					    		ll.removeView(vv);
					    	
					    	generateScreen(4);
				
					    		break;
	    				}
				
	    			}
				
	    		};
	    		
	       

	    	
	    		
	    		
				@Override
				public void onClick(View v) {
					flag=true;
					switch (v.getId()) {
			        case R.id.primobottone:
			        iw.setBackgroundDrawable(Immaginesfondoclick);
			        finish();
			            break;
			        case R.id.secondobottone:
			        	iw2.setBackgroundDrawable(Immaginesfondoclick);
			        	status=1;
			        	finish();
			        	//System.exit(0);
			        	break;
			        case R.id.terzobottone:
			        	iw3.setBackgroundDrawable(Immaginesfondoclick);
			        	status=2;
			        	finish();
			        	//System.exit(0);
			        	break;
			       
			        case R.id.bar1:
			        	//a11.setBackgroundColor(R.color.arancione);
			        	if(!att.getEmail().equalsIgnoreCase("nessuna email disponibile")){
			        	final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
			        	emailIntent .setType("text/plain"); 
			        	
			        	emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{att.getEmail()}); 
			        	emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "Oggetto"); 
			        	//emailIntent .putExtra(android.content.Intent.EXTRA_TEXT, att.getEmail()); 
			        	//emailIntent .putExtra(android.content.Intent.EXTRA_TEXT, "Inserisci testo");
			        	this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
			        	}
			        	else{showInfo("Nessuna email disponibile");}
			        	break;
			        case R.id.bar2:
			        	//a22.setBackgroundColor(R.color.arancione);
			        	if(!att.getTelefono().equalsIgnoreCase("telefono non disponibile")){
			        	Intent call = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+att.getTelefono()));
			        	startActivity(call);
			        	}
			        	else{showInfo("Numero di telefono non disponibile");}
			        	break;
			        case R.id.bar3:
			        	//a33.setBackgroundColor(R.color.arancione);
			        	//FAX
			        	
			        	//Intent browser =new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("www.google.com"));
			        	//startActivity(browser);
			        	showInfo("Fax non disponibile in questa applicazione");
			        	
			        	break;
			        case R.id.bar4:
			        	//a44.setBackgroundColor(R.color.arancione);
			        	if(!att.getSito().equalsIgnoreCase("nessun sito web disponibile")){
			        	Intent intent = new Intent(Intent.ACTION_VIEW);
			        	Uri uri = Uri.parse(att.getSito());
			        	intent.setData(uri);
			        	startActivity(intent);
			        	}
			        	else{
			        		showInfo("Nessun sito web disponibile");
			        	}
			        	break;
					
					case R.id.bar5:
						//a55.setBackgroundColor(R.color.arancione);
						if (att.getStringaParametriStreetView() != null){
					     	Intent streetViewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(att.getStringaParametriStreetView()));
					     	startActivity(streetViewIntent);
					     	
						}
						else
							showInfo("Funzione StreetView non disponibile");
			        	break;
				}
					
				}


				@Override
				protected boolean isRouteDisplayed() {
					// TODO Auto-generated method stub
					return false;
				}
				
				public HelloItemizedOverlay aggiungiAttivitacliccata(Drawable icona,GeoPoint point)
				{
				//Drawable icona=att.getLogoMappa();
				//Drawable icona=this.getResources().getDrawable(R.drawable.aa_logo_min_mediolanum);
				//Drawable iconaIO=this.getResources().getDrawable(R.drawable.frecciaverde);
				Intent apriPopupBar = new Intent(this, TemplateMenuAttivita.class);	//va modificata la classe richiamata dall'intento
				HelloItemizedOverlay io = new HelloItemizedOverlay(icona,apriPopupBar,this);
				//HelloItemizedOverlay ioIO = new HelloItemizedOverlay(iconaIO,apriPopupBar,this);
				//GeoPoint point1 = new GeoPoint(37516608, 15104628);
				//OverlayItem overlayitem = new OverlayItem(point2, "", "");
				OverlayItem overlayitem = new OverlayItem(point, "", "");
				io.addOverlay(overlayitem);
				//DA SISTEMARE
				return io;
				}
				public HelloItemizedOverlay aggiungiSegnaposto(Drawable icona,GeoPoint point)
				{
				//Drawable icona=att.getLogoMappa();
				//Drawable icona=this.getResources().getDrawable(R.drawable.aa_logo_min_mediolanum);
				//Drawable iconaIO=this.getResources().getDrawable(R.drawable.frecciaverde);
				Intent apriPopupBar = new Intent(this, TemplateMenuAttivita.class);	//va modificata la classe richiamata dall'intento
				HelloItemizedOverlay io = new HelloItemizedOverlay(icona,apriPopupBar,this,0);
				//HelloItemizedOverlay ioIO = new HelloItemizedOverlay(iconaIO,apriPopupBar,this);
				//GeoPoint point1 = new GeoPoint(37516608, 15104628);
				//OverlayItem overlayitem = new OverlayItem(point2, "", "");
				OverlayItem overlayitem = new OverlayItem(point, "", "");
				io.addOverlay(overlayitem);
				//DA SISTEMARE
				return io;
				}
				
	       

	    		public void showInfo(String mSG)
	    		{
	    		AlertDialog alertDialog = new AlertDialog.Builder(this).create();
	    		alertDialog.setTitle("Info");
	    		alertDialog.setMessage(mSG);
	    		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
	    			public void onClick(DialogInterface dialog, int which)
	    				{
	    				return;
	    				}
	    			}); 
	    		alertDialog.show();
	    		}
	    		public void onPause(){
	    			super.onPause();
	    			System.out.println("*****************************on pause");
	    			//System.exit(0);
	    			
	    			}
	    		public void onStop(){
	    			super.onStop();
	    			//System.exit(0);
	    			System.out.println("*****************************on stop");
	    			}
	    		public void onDestroy(){
	    			super.onDestroy();
	    			//System.exit(0);
	    			System.out.println("*****************************"+ATTIVITA_CLICCATA+" on destroy");
	    			}
	    		
}

